//
//  BaseTabBarController.m
//  Connections
//
//  Created by beisheng03 on 2017/9/28.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "BaseTabBarController.h"
#import "BaseNavigationController.h"
#import "HomeViewController.h"
#import "MessageController.h"
#import "MeViewController.h"
#import "AddressBookVC.h"

@interface BaseTabBarController ()

@end

@implementation BaseTabBarController


// 加载类进内存的时候调用,只会调用一次
+ (void)load
{
    // 获取当前类下所有的tabBarItem
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    
    // 设置选中标题的颜色
    // 创建富文本属性字典
    NSMutableDictionary *testAttr = [NSMutableDictionary dictionary];
    
    // 描述颜色
    testAttr[NSForegroundColorAttributeName] = colorWith(47, 162, 19);
    
    // 设置标题的富文本属性
    [item setTitleTextAttributes:testAttr forState:UIControlStateSelected];
    
    // 问题:设置字体颜色不好使,注意:一定要先设置正常状态下字体大小
    // 设置正常状态下字体
    NSMutableDictionary *testAttrNor = [NSMutableDictionary dictionary];
    
    // 描述字体
    testAttrNor[NSFontAttributeName] = [UIFont systemFontOfSize:13];
    
    // 设置标题的富文本属性
    [item setTitleTextAttributes:testAttrNor forState:UIControlStateNormal];
}






- (void)viewDidLoad {
    [super viewDidLoad];
    // 1 添加UITabBarController子控制器
    [self setupAllChildViewController];
    
    // 2 设置tabBar上所有按钮内容
    [self setupAllTabBarButton];
    
    
    
}



#pragma mark - 添加所有的子控制器
- (void)setupAllChildViewController
{
    // 首页
    HomeViewController *homeVC = [[HomeViewController alloc] init];
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:homeVC];
    [self addChildViewController:nav];

    // 通讯录
    AddressBookVC *addressBookVc = [[AddressBookVC alloc] initWithStyle:UITableViewStylePlain];
    BaseNavigationController *nav1 = [[BaseNavigationController alloc] initWithRootViewController:addressBookVc];
    [self addChildViewController:nav1];
    
    // 消息
    MessageController *messageVc = [[MessageController alloc] init];
    BaseNavigationController *nav3 = [[BaseNavigationController alloc] initWithRootViewController:messageVc];
    [self addChildViewController:nav3];

//    // 我
//    MeViewController *meVc = [[MeViewController alloc] init];
//    BaseNavigationController *nav4 = [[BaseNavigationController alloc] initWithRootViewController:meVc];
//    [self addChildViewController:nav4];
    
    
    
    
    // Storyboard必须手动加载 1.加载Storyboard文件 2.加载箭头指向控制器
    // 加载Storyboard文件
//    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:NSStringFromClass([XMGMeViewController class]) bundle:nil];
//
//    // instantiateInitialViewController:加载箭头指向控制器
//    XMGMeViewController *meVc = [storyboard instantiateInitialViewController];
//
//    XMGNavigationController *nav4 = [[XMGNavigationController alloc] initWithRootViewController:meVc];
//    // initWithRootViewController -> push
//    [self addChildViewController:nav4];
}



#pragma mark - 设置所有的TabBarButton
- (void)setupAllTabBarButton
{
    
    // 精华按钮 0个子控制器
    UINavigationController *nav = self.childViewControllers[0];
    nav.tabBarItem.title = @"首页";
    nav.tabBarItem.image = [UIImage imageNamed:@"tabbar_mainframeHL"];
    // 让图片不要渲染imageWithOriginalRender
    nav.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_mainframeHL"];
    
    // 新帖按钮 1
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"通讯录";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabbar_contactsHL"];
    nav1.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_contactsHL"];
    
    // 关注按钮 2
    UINavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.title = @"消息";
    nav2.tabBarItem.badgeValue = @"3";
    nav2.tabBarItem.image = [UIImage imageNamed:@"tabbar_mainframeHL"];
    nav2.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_mainframeHL"];
    

//    // 关注按钮 2
//    UINavigationController *nav3 = self.childViewControllers[3];
//    nav3.tabBarItem.title = @"个人中心";
//    nav3.tabBarItem.image = [UIImage imageNamed:@"tabbar_me"];
//    nav3.tabBarItem.selectedImage = [UIImage imageWithOriginalName:@"tabbar_meHL"];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
